package com.nsapi.niceschoolapi.controller;

import com.nsapi.niceschoolapi.common.base.PageData;
import com.nsapi.niceschoolapi.common.config.MySysUser;
import com.nsapi.niceschoolapi.entity.EvaluateListDB;
import com.nsapi.niceschoolapi.entity.EvaluateRecordDB;
import com.nsapi.niceschoolapi.entity.StudentDB;
import com.nsapi.niceschoolapi.service.EvaluateService;
import com.nsapi.niceschoolapi.service.StudentService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Controller
public class EvaluateController {
    @Resource
    private EvaluateService evaluateService;

    @Resource
    private StudentService studentService;
    //进入网上教评
    @RequestMapping(value = "/appraise/seltch")
    public String seltch(){
        return "view/appraise/seltch";
    }
    //查询是否已经教评过
    @RequestMapping(value = "/appraise/selonestate")
    @ResponseBody
    public boolean selonestate(String tchid){
        int result=evaluateService.count(tchid);
        if (result>0){
          return true;
        }else{
            return false;
        }
    }
    //查询所有教评信息
    @RequestMapping(value = "/appraise/findalltm")
    @ResponseBody
    public PageData<EvaluateListDB> findalltm(){
        PageData<EvaluateListDB> pageData=new PageData<>();
        List<EvaluateListDB> evaluateList=evaluateService.evaluateList();
        pageData.setData(evaluateList);
        return pageData;
    }

    //添加教评记录
    @RequestMapping(value = "/appraise/addoneappraise")
    @ResponseBody
        public Boolean addoneappraise(EvaluateRecordDB evaluateRecordDB){
        StudentDB studentDB=studentService.student(MySysUser.loginName());
        evaluateRecordDB.setStuid(studentDB.getStuid());
        evaluateRecordDB.setCreate_by(MySysUser.id());
        evaluateRecordDB.setCreate_date(new Date());
        int result=evaluateService.addEvaluate(evaluateRecordDB);
        if (result>0){
            return true;
        }else {
            return false;
        }
    }
}
